package com.chenyongjing.design.pattern.iterator.course;

/**
 * @Author chen
 * @Date 2022/11/19 21:49
 */
public class Test {
    public static void main(String[] args) {
        Course java = new Course("Java基础课程");
        Course javaFrame = new Course("java框架");
        Course design = new Course("设计模式");
        Course ai = new Course("人工智能");

        ICourseAggregate aggregate = new CourseAggregateImpl();
        aggregate.add(java);
        aggregate.add(javaFrame);
        aggregate.add(design);
        aggregate.add(ai);

        System.out.println("================课程列表===============");
        printCourse(aggregate);

        aggregate.remove(java);
        System.out.println("============删除后课程列表===============");
        printCourse(aggregate);
    }

    private static void printCourse(ICourseAggregate aggregate) {
        Iterator<Course> i = aggregate.iterator();
        while (i.hasNext()){
            Course course = i.next();
            System.out.println(course.getName());
        }
    }
}
